home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / plugindialog.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-28  |  12.5 KB  |  293 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from base.g import *
  5. from base import device, utils
  6. from prnt import cups
  7. from base.codes import *
  8. from ui_utils import *
  9. from installer.core_install import CoreInstall
  10. from installer.core_install import PLUGIN_INSTALL_ERROR_NONE, PLUGIN_INSTALL_ERROR_PLUGIN_FILE_NOT_FOUND, PLUGIN_INSTALL_ERROR_DIGITAL_SIG_NOT_FOUND, PLUGIN_INSTALL_ERROR_DIGITAL_SIG_BAD, PLUGIN_INSTALL_ERROR_PLUGIN_FILE_CHECKSUM_ERROR, PLUGIN_INSTALL_ERROR_NO_NETWORK, PLUGIN_INSTALL_ERROR_DIRECTORY_ERROR, PLUGIN_INSTALL_ERROR_UNABLE_TO_RECV_KEYS
  11. from PyQt4.QtCore import *
  12. from PyQt4.QtGui import *
  13. from plugindialog_base import Ui_Dialog
  14. PAGE_SOURCE = 0
  15. PAGE_MAX = 1
  16.  
  17. class PluginDialog(QDialog, Ui_Dialog):
  18.     
  19.     def __init__(self, parent, install_mode = PLUGIN_NONE, plugin_reason = PLUGIN_REASON_NONE):
  20.         QDialog.__init__(self, parent)
  21.         self.install_mode = install_mode
  22.         self.plugin_reason = plugin_reason
  23.         self.plugin_path = None
  24.         self.result = False
  25.         self.core = CoreInstall()
  26.         self.core.set_plugin_version()
  27.         self.setupUi(self)
  28.         self.user_settings = UserSettings()
  29.         self.user_settings.load()
  30.         self.user_settings.debug()
  31.         self.initUi()
  32.         QTimer.singleShot(0, self.showSourcePage)
  33.  
  34.     
  35.     def isPluginInstalled(self):
  36.         return self.core.check_for_plugin()
  37.  
  38.     
  39.     def initUi(self):
  40.         self.connect(self.CancelButton, SIGNAL('clicked()'), self.CancelButton_clicked)
  41.         self.connect(self.NextButton, SIGNAL('clicked()'), self.NextButton_clicked)
  42.         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
  43.         self.PLUGIN_REASON_TEXT = {
  44.             PLUGIN_REASON_NONE: None,
  45.             PLUGIN_REASON_PRINTING_SUPPORT: self._PluginDialog__tr('This plugin will enable printing support.'),
  46.             PLUGIN_REASON_FASTER_PRINTING: self._PluginDialog__tr('This plugin will enhance print speed.'),
  47.             PLUGIN_REASON_BETTER_PRINTING_PQ: self._PluginDialog__tr('This plugin will enhance print quality.'),
  48.             PLUGIN_REASON_PRINTING_FEATURES: self._PluginDialog__tr('This plugin will add printing features.'),
  49.             PLUGIN_REASON_RESERVED_10: None,
  50.             PLUGIN_REASON_RESERVED_20: None,
  51.             PLUGIN_REASON_SCANNING_SUPPORT: self._PluginDialog__tr('This plugin will enable scanning support.'),
  52.             PLUGIN_REASON_FASTER_SCANNING: self._PluginDialog__tr('This plugin will enhance scanning speed.'),
  53.             PLUGIN_REASON_BETTER_SCANNING_IQ: self._PluginDialog__tr('This plugin will enhance scanning image quality.'),
  54.             PLUGIN_REASON_RESERVED_200: None,
  55.             PLUGIN_REASON_RESERVED_400: None,
  56.             PLUGIN_REASON_FAXING_SUPPORT: self._PluginDialog__tr('This plugin will enable faxing support.'),
  57.             PLUGIN_REASON_FAX_FEATURES: self._PluginDialog__tr('This plugin will enhnace faxing features.'),
  58.             PLUGIN_REASON_RESERVED_20000: None,
  59.             PLUGIN_REASON_RESERVED_40000: None }
  60.  
  61.     
  62.     def showSourcePage(self):
  63.         reason_text = self.plugin_reason_text()
  64.         if reason_text is not None:
  65.             if self.install_mode == PLUGIN_REQUIRED:
  66.                 self.TitleLabel.setText(self._PluginDialog__tr('An additional driver plug-in is required to operate this printer. You may download the plug-in directly from an HP authorized server (recommended), or, if you already have a copy of the file, you can specify a path to the file (advanced). <br><br>%1').arg(reason_text))
  67.                 self.SkipRadioButton.setEnabled(False)
  68.             elif self.install_mode == PLUGIN_OPTIONAL:
  69.                 self.TitleLabel.setText(self._PluginDialog__tr('An optional driver plug-in is available to enhance the operation of this printer. You may download the plug-in directly from an HP authorized server (recommended), skip this installation (not recommended), or, if you already have a copy of the file, you can specify a path to the file (advanced).<br><br>%1').arg(reason_text))
  70.             
  71.         
  72.         self.connect(self.DownloadRadioButton, SIGNAL('toggled(bool)'), self.DownloadRadioButton_toggled)
  73.         self.connect(self.CopyRadioButton, SIGNAL('toggled(bool)'), self.CopyRadioButton_toggled)
  74.         self.connect(self.SkipRadioButton, SIGNAL('toggled(bool)'), self.SkipRadioButton_toggled)
  75.         self.connect(self.PathLineEdit, SIGNAL('textChanged(const QString &)'), self.PathLineEdit_textChanged)
  76.         self.connect(self.BrowseToolButton, SIGNAL('clicked()'), self.BrowseToolButton_clicked)
  77.         self.BrowseToolButton.setIcon(QIcon(load_pixmap('folder_open', '16x16')))
  78.         self.displayPage(PAGE_SOURCE)
  79.  
  80.     
  81.     def DownloadRadioButton_toggled(self, b):
  82.         if b:
  83.             self.PathLineEdit.setEnabled(False)
  84.             self.BrowseToolButton.setEnabled(False)
  85.             self.NextButton.setEnabled(True)
  86.             
  87.             try:
  88.                 self.PathLineEdit.setStyleSheet('')
  89.             except AttributeError:
  90.                 pass
  91.  
  92.             self.plugin_path = None
  93.         
  94.  
  95.     
  96.     def CopyRadioButton_toggled(self, b):
  97.         if b:
  98.             self.PathLineEdit.setEnabled(True)
  99.             self.BrowseToolButton.setEnabled(True)
  100.             self.plugin_path = unicode(self.PathLineEdit.text())
  101.             self.setPathIndicators()
  102.         
  103.  
  104.     
  105.     def SkipRadioButton_toggled(self, b):
  106.         if b:
  107.             self.PathLineEdit.setEnabled(False)
  108.             self.BrowseToolButton.setEnabled(False)
  109.             self.NextButton.setEnabled(True)
  110.             
  111.             try:
  112.                 self.PathLineEdit.setStyleSheet('')
  113.             except AttributeError:
  114.                 pass
  115.  
  116.             self.plugin_path = None
  117.         
  118.  
  119.     
  120.     def PathLineEdit_textChanged(self, t):
  121.         self.plugin_path = unicode(t)
  122.         self.setPathIndicators()
  123.  
  124.     
  125.     def setPathIndicators(self):
  126.         ok = True
  127.         if (not (self.plugin_path) or self.plugin_path) and os.path.isdir(self.plugin_path):
  128.             self.PathLineEdit.setToolTip(self._PluginDialog__tr("You must specify a path to the '%1' file.").arg(self.core.plugin_name))
  129.             ok = False
  130.         elif os.path.basename(self.plugin_path) != self.core.plugin_name:
  131.             self.PathLineEdit.setToolTip(self._PluginDialog__tr("The plugin filename must be '%1'.").arg(self.core.plugin_name))
  132.             ok = False
  133.         
  134.         if not ok:
  135.             
  136.             try:
  137.                 self.PathLineEdit.setStyleSheet('background-color: yellow; ')
  138.             except AttributeError:
  139.                 pass
  140.  
  141.             self.NextButton.setEnabled(False)
  142.         else:
  143.             
  144.             try:
  145.                 self.PathLineEdit.setStyleSheet('')
  146.             except AttributeError:
  147.                 pass
  148.  
  149.             self.NextButton.setEnabled(True)
  150.             self.PathLineEdit.setToolTip(QString(''))
  151.  
  152.     
  153.     def BrowseToolButton_clicked(self):
  154.         t = unicode(self.PathLineEdit.text())
  155.         if not os.path.exists(t):
  156.             path = unicode(QFileDialog.getOpenFileName(self, self._PluginDialog__tr('Select Plug-in File'), self.user_settings.working_dir, self._PluginDialog__tr('Plugin Files (*.run)')))
  157.         
  158.         if path:
  159.             self.plugin_path = path
  160.             self.PathLineEdit.setText(self.plugin_path)
  161.             self.user_settings.working_dir = self.plugin_path
  162.             self.user_settings.save()
  163.         
  164.         self.setPathIndicators()
  165.  
  166.     
  167.     def displayPage(self, page):
  168.         self.updateStepText(page)
  169.         self.StackedWidget.setCurrentIndex(page)
  170.  
  171.     
  172.     def CancelButton_clicked(self):
  173.         self.close()
  174.  
  175.     
  176.     def NextButton_clicked(self):
  177.         if self.SkipRadioButton.isChecked():
  178.             log.debug('Skipping plug-in installation.')
  179.             self.close()
  180.             return None
  181.         beginWaitCursor()
  182.         
  183.         try:
  184.             if self.plugin_path is None:
  185.                 plugin_conf_url = self.core.get_plugin_conf_url()
  186.                 log.info('Downloading configuration file from: %s' % plugin_conf_url)
  187.                 (self.plugin_path, size, checksum, timestamp, ok) = self.core.get_plugin_info(plugin_conf_url, self.plugin_download_callback)
  188.                 log.debug('path=%s, size=%d, checksum=%s, timestamp=%f, ok=%s' % (self.plugin_path, size, checksum, timestamp, ok))
  189.                 if not self.plugin_path.startswith('http://') and not self.plugin_path.startswith('file://'):
  190.                     self.plugin_path = 'file://' + self.plugin_path
  191.                 
  192.             elif not self.plugin_path.startswith('http://'):
  193.                 self.plugin_path = 'file://' + self.plugin_path
  194.             
  195.             (size, checksum, timestamp) = (0, '', 0)
  196.             log.info('Downloading plug-in from: %s' % self.plugin_path)
  197.             (status, ret) = self.core.download_plugin(self.plugin_path, size, checksum, timestamp, self.plugin_download_callback)
  198.             if status in (PLUGIN_INSTALL_ERROR_UNABLE_TO_RECV_KEYS, PLUGIN_INSTALL_ERROR_DIGITAL_SIG_NOT_FOUND):
  199.                 endWaitCursor()
  200.                 if QMessageBox.question(self, self._PluginDialog__tr('Digital signature download failed'), self._PluginDialog__tr('<b>The download of the digital signature file failed.</b><p>Without this file, it is not possible to authenticate and validate the plug-in prior to installation.</p>Do you still want to install the plug-in?'), QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
  201.                     self.core.delete_plugin()
  202.                     self.close()
  203.                     return None
  204.             elif status != PLUGIN_INSTALL_ERROR_NONE:
  205.                 if status == PLUGIN_INSTALL_ERROR_PLUGIN_FILE_NOT_FOUND:
  206.                     desc = self._PluginDialog__tr('<b>ERROR: Plug-in file not found (server returned 404 or similar error).</b><p>Error code: %1</p>').arg(str(ret))
  207.                 elif status == PLUGIN_INSTALL_ERROR_DIGITAL_SIG_BAD:
  208.                     desc = self._PluginDialog__tr('<b>ERROR: Plug-in file does not match its digital signature.</b><p>File may have been corrupted or altered.</p><p>Error code: %1</p>').arg(str(ret))
  209.                 elif status == PLUGIN_INSTALL_ERROR_PLUGIN_FILE_CHECKSUM_ERROR:
  210.                     desc = self._PluginDialog__tr('<b>ERROR: Plug-in file does not match its checksum. File may have been corrupted or altered.')
  211.                 elif status == PLUGIN_INSTALL_ERROR_NO_NETWORK:
  212.                     desc = self._PluginDialog__tr('<b>ERROR: Unable to connect to network to download the plug-in.</b><p>Please check your network connection and try again.</p>')
  213.                 elif status == PLUGIN_INSTALL_ERROR_DIRECTORY_ERROR:
  214.                     desc = self._PluginDialog__tr('<b>ERROR: Unable to create the plug-in directory.</b><p>Please check your permissions and try again.</p>')
  215.                 
  216.                 self.core.delete_plugin()
  217.                 endWaitCursor()
  218.                 FailureUI(self, desc)
  219.                 self.close()
  220.                 return None
  221.             if not self.core.run_plugin(GUI_MODE, self.plugin_install_callback):
  222.                 self.core.delete_plugin()
  223.                 endWaitCursor()
  224.                 FailureUI(self, self._PluginDialog__tr('Plug-in install failed.'))
  225.                 self.close()
  226.                 return None
  227.             cups_devices = device.getSupportedCUPSDevices([
  228.                 'hp'])
  229.             for dev in cups_devices:
  230.                 mq = device.queryModelByURI(dev)
  231.                 if mq.get('fw-download', False):
  232.                     log.info(log.bold('\nDownloading firmware to device %s...' % dev))
  233.                     
  234.                     try:
  235.                         d = None
  236.                         
  237.                         try:
  238.                             d = device.Device(dev)
  239.                         except Error:
  240.                             self.core.run_plugin(GUI_MODE, self.plugin_install_callback)
  241.                             self.core.run_plugin(GUI_MODE, self.plugin_install_callback)
  242.                             log.error('Error opening device.')
  243.                             endWaitCursor()
  244.                             FailureUI(self, self._PluginDialog__tr('<b>Firmware download to device failed.</b><p>%1</p>').arg(dev))
  245.                             continue
  246.                         except:
  247.                             self.core.run_plugin(GUI_MODE, self.plugin_install_callback)
  248.  
  249.                         if d.downloadFirmware():
  250.                             log.info('Firmware download successful.\n')
  251.                         else:
  252.                             endWaitCursor()
  253.                             FailureUI(self, self._PluginDialog__tr('<b>Firmware download to device failed.</b><p>%1</p>').arg(dev))
  254.                     finally:
  255.                         pass
  256.  
  257.                     continue
  258.                 self.core.run_plugin(GUI_MODE, self.plugin_install_callback)
  259.         finally:
  260.             endWaitCursor()
  261.  
  262.         self.core.delete_plugin()
  263.         SuccessUI(self, self._PluginDialog__tr('<b>Plug-in installation successful.</b>'))
  264.         self.result = True
  265.         self.close()
  266.  
  267.     
  268.     def plugin_download_callback(self, c, s, t):
  269.         pass
  270.  
  271.     
  272.     def plugin_install_callback(self, s):
  273.         print s
  274.  
  275.     
  276.     def updateStepText(self, p):
  277.         self.StepText.setText(self._PluginDialog__tr('Step %1 of %2').arg(p + 1).arg(PAGE_MAX + 1))
  278.  
  279.     
  280.     def plugin_reason_text(self):
  281.         
  282.         try:
  283.             return self.PLUGIN_REASON_TEXT[self.plugin_reason]
  284.         except KeyError:
  285.             return None
  286.  
  287.  
  288.     
  289.     def __tr(self, s, c = None):
  290.         return qApp.translate('PluginDialog', s, c)
  291.  
  292.  
  293.